#include "flash.h"

#define FLASH_SECTOR62_ADRR             (0x0007C000u)


void writeFlashPage(uint32_t address,uint32_t *data, uint8_t len)
{
    /* Unlock EFM. */
    EFM_Unlock();

    /* Enable flash. */
    EFM_FlashCmd(Enable);
    /* Wait flash ready. */
    while(Set != EFM_GetFlagStatus(EFM_FLAG_RDY))
    {
        ;
    }

    /* Erase sector 62. */
    EFM_SectorErase(address);

    uint32_t u32Addr = address;

    for(uint8_t i = 0u; i < len; i++)
    {
        EFM_SingleProgram(u32Addr,data[i]);
        u32Addr += 4u;
    }

    /* Lock EFM. */
    EFM_Lock();
}

void readFlashPage(uint32_t address,uint32_t *data, uint8_t len)
{
    uint32_t u32Addr = address;
    for(uint8_t i = 0u; i < len; i++)
    {
        data[i] = *((uint32_t *)u32Addr);
        u32Addr += 4u;
    }
}
